<div class="modal-header">
    <button type="button" class="close" data-dismiss="modal" close="true">
        <span aria-hidden="true">×</span>
    </button>
    <h4 class="modal-title">
        <span class="fa fa-legal"></span>&nbsp;修改
    </h4>
</div>
<style>
    .config_img{height:45px;margin-top:15px;}

</style>
<div class="modal-body">

    <div class="new-content">
        <form name="add_form" class="form-horizontal layui-form">

            <div class="form-group">
                <label class="col-sm-2 control-label">所属类型:</label>
                <div class="col-sm-8">
                    <select name="type" lay-verify="type" lay-filter="type" >
                        <option value="1" {if condition="$detail['type'] eq 1"} selected {/if}>项目类别</option>
                        <option value="2" {if condition="$detail['type'] eq 2"} selected {/if}>产业链</option>
                        <option value="3" {if condition="$detail['type'] eq 3"} selected {/if}>企业类型</option>
                        <option value="4" {if condition="$detail['type'] eq 4"} selected {/if}>一级分类</option>
                        <option value="5" {if condition="$detail['type'] eq 5"} selected {/if}>项目流程</option>
                        <option value="6" {if condition="$detail['type'] eq 6"} selected {/if}>问题类型</option>
                        <option value="20" {if condition="$detail['type'] eq 20"} selected {/if}>政府投资</option>
                        <option value="21" {if condition="$detail['type'] eq 21"} selected {/if}>产业类</option>
                    </select>
                </div>
            </div>

            <div class="form-group menuTop" {if condition="$detail['type'] neq 3"} style="display: none" {/if}>
                <label class="col-sm-2 control-label">一级分类:</label>
                <div class="col-sm-8">
                    <select name="menuTop">
                        <option value="0">请选择分类</option>
                        {volist name="pro_type" id="vo"}
                        <option value="{$key}" {if condition="$detail['menuTop'] eq $key"} selected {/if}>{$vo}</option>
                        {/volist}
                    </select>
                </div>
            </div>

            <div class="form-group parent" {if condition="count($parent) gt 0"} style="display: none" {/if}>
                <label class="col-sm-2 control-label">上级分类:</label>
                <div class="col-sm-8">
                    <select name="pid">
                        <option value="0">顶级分类</option>
                        {volist name="parent" id="vo"}
                        <option value="{$vo.id}" {if condition="$detail['pid'] eq $vo['id']"} selected {/if}>{$vo.name}</option>
                        {/volist}
                    </select>
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-2 control-label">*名称:</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control" name="name" placeholder="名称" value="{$detail.name}">
                </div>
            </div>

            <div class="form-group">
                <label class="col-sm-2 control-label">*说明:</label>
                <div class="col-sm-8">
                    <input type="text" class="form-control" name="desc" placeholder="说明" value="{$detail.desc}">
                </div>
            </div>


            <div class="form-group js_photos">
                <label class="col-sm-2 control-label"> *缩略图</label>
                <div class="col-sm-8 logo">
                    <div class="input-group ">
                        <input type="file" name="" class="do_upload" data-val="image"  style="display: none">
                        <input type="text" class="form-control image" name="image" disabled="" value="{$detail.image}" >
                        <input type="hidden" class="form-control image" name="image" value="{$detail.image}" >
                        <span class="group-span-filestyle input-group-btn" tabindex="0">
                            <label class="btn btn-default id_photos" data-original-title="" title="">
                                <span class="glyphicon glyphicon-folder-open"></span>
                                上传
                            </label>
                        </span>
                        </span>
                    </div>
                    {if condition="$detail['image'] neq ''"}
                    <img class="config_img" src="{$detail.image}" >
                    {/if}
                </div>
            </div>


            <div class="form-group">
                <label class="col-sm-2 control-label">状态:</label>
                <div class="col-sm-8">
                    <select name="status">
                        <option value="1" {if condition="$detail['status'] eq 1"} selected {/if}>启用</option>
                        <option value="2" {if condition="$detail['status'] eq 2"} selected {/if}>禁用</option>
                    </select>
                </div>
            </div>

            <div class="form-group library" {if condition="$detail['type'] neq 20 & $detail['type'] neq 21"} style="display: none" {/if} >
                <label class="col-sm-2 control-label">所属库:</label>
                <div class="col-sm-8">
                    <input type="checkbox" name="library[]" value="2" title="预备库" <?php if(in_array(2,$detail['library'])){ ?> checked="" <?php }?> >
                    <input type="checkbox" name="library[]" value="3" title="开工库" <?php if(in_array(3,$detail['library'])){ ?> checked="" <?php }?> >
                    <input type="checkbox" name="library[]" value="4" title="重点库" <?php if(in_array(4,$detail['library'])){ ?> checked="" <?php }?> >
                </div>
            </div>

            <input type="hidden" name="id" value="{$detail.id}">
        </form>
    </div>

</div>
<div class="modal-footer">
    <button type="button" class="btn btn-default btn-sm" close="true">关闭</button>
    <button type="button" class="btn btn-primary btn-sm" _event="edit">保存</button>
</div>
<script>

    $(".id_photos").click(function () {
        $(this).parent().parent().find(".do_upload").click();
    });

    $('.js_photos').on('change','.do_upload',function(){
        var content = $(this).attr("data-val");
        var formData = new FormData();
        var name = $($(this)).val();
        var files = $($(this))[0].files[0];
        formData.append("file", files);
        formData.append("name", name);
        //另外加的参数
        formData.append("act", "PostImg");
        // var index = layer.msg('正在提交中....');

        $.ajax({
            url: "{:URL('common/upload/ad_upload')}",
            type: 'POST',
            data: formData,
            processData: false,
            contentType: false,
            dataType: 'json',
            success:function (res) {
                $("."+content).val(res.path);
                $("."+content).find("img").attr("src",res.path);
            }
            ,error:function (res) {
                alert('错误');
            }
        });
    })
    layui.use(['form'], function() {
        var form = layui.form
            , layer = layui.layer;
        var layedit = layui.layedit;
        var  tree = layui.tree;
        var util = layui.util;

        //触发二级联动
        form.on('select(type)', function (data) {
            //触发联动

            var id = data.value;
            /*if(id==3){
                $(".menuTop").show();
                $(".parent").hide();
            }else{
                $(".menuTop").hide();
                $(".parent").hide();
            }*/

            if(id==4 || id==5|| id==7|| id==8 || id==20 || id==21){

                //触发联动
                $.ajax({
                    type: 'post',
                    url: "{:URL('project/dictionaries/superiorApi')}",
                    data: {type: id},
                    dataType: 'JSON',
                    success: function (res) {
                        var data = res.data;
                        //生成楼栋信息
                        var html = '<option value="">顶级分类</option>';
                        $.each(data, function(e,v){
                            html +='<option value="'+v.id+'" >'+v.name+'</option>';
                            // $.each(v.child, function(e1,v1){
                            //     html +='<option value="'+v1.id+'" >--'+v1.name+'</option>';
                            // });
                        });
                        $('select[name="pid"]').html(html);
                        form.render('select');
                    },
                    error: function (res) {
                    }
                });

                if(id==20 |  id==21){
                    $(".library").show();
                }else{
                    $(".library").hide();
                }

                $(".menuTop").hide();
                $(".parent").show();
            }else{
                $(".library").hide();
                $(".menuTop").show();
                $(".parent").hide();
            }


        });


        layui.form.render('select');
        form.render();
    });
</script>